import 'package:flutter/material.dart';

class RadioDemo extends StatefulWidget {
  const RadioDemo({super.key});

  @override
  State<RadioDemo> createState() => _RadioDemoState();
}

class _RadioDemoState extends State<RadioDemo> {

  int _radioGroupA = 0;

  void _handleRadioValueChanged(value) {
    if (value != null) {
      setState(() {
        _radioGroupA = value;
        debugPrint('$value');
      });  
    }

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('RadioDemo'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text('RadioGroupValue:$_radioGroupA'),
          const SizedBox(height: 20,),
          RadioListTile(
            value: 1,
            groupValue: _radioGroupA,
            onChanged: _handleRadioValueChanged,
            title: const Text('单选Option A'),
            subtitle: const Text('描述Description'),
            secondary: const Icon(Icons.filter_1),
            selected: _radioGroupA == 1,
          ),
          RadioListTile(
            value: 2,
            groupValue: _radioGroupA,
            onChanged: _handleRadioValueChanged,
            title: const Text('单选Option B'),
            subtitle: const Text('描述Description'),
            secondary: const Icon(Icons.filter_2),
            
            selected: _radioGroupA == 2,
          ),
          RadioListTile(
            value: 3,
            groupValue: _radioGroupA,
            onChanged: _handleRadioValueChanged,
            title: const Text('单选Option C'),
            subtitle: const Text('描述Description'),
            secondary: const Icon(Icons.filter_3),
            
            selected: _radioGroupA == 3,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Radio(
                value: 4,
                groupValue: _radioGroupA,
                onChanged: _handleRadioValueChanged,
              ),
              Radio(
                value: 5,
                groupValue: _radioGroupA,
                onChanged: _handleRadioValueChanged,
              ),
              Radio(
                value: 6,
                groupValue: _radioGroupA,
                onChanged: _handleRadioValueChanged,
              ),
            ],
          )
        ],
      ),
    );
  }
}
